package cn.lanqiao.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.lanqiao.entity.Pages;
import cn.lanqiao.entity.Teacher;
import cn.lanqiao.service.TeacherService;
/**
 * 学生管理模块
 * @author yejun
 */
@Service
public class TeacherServiceImpl implements TeacherService {

	@Autowired
	private cn.lanqiao.mapper.TeacherMapper teacherMapper;

	//分页
	@Override
	public Pages<Teacher> teacherPage(int indexPage, int pageSize, String searchkey) {
		Pages<Teacher> page = new Pages<Teacher>();
		//当前页面indexPage
		page.setIndexPage(indexPage);
		//总记录数totalData
		int totalData = teacherMapper.count(searchkey);
		page.setTotalData(totalData);
		//当前页面记录数pageSize;
		page.setPageSize(pageSize);
		//总页数totalPages
		int totalPages = totalData % pageSize ==0 ? totalData / pageSize : totalData/ pageSize + 1;
		page.setTotalPages(totalPages);
		
		Map<String,Object> map = new HashMap<String,Object>();
		int startindex = (indexPage -1) * pageSize;
		int endindex = pageSize;
		
		map.put("startindex", startindex);
		map.put("endindex", endindex);
		map.put("searchkey", searchkey);
		
		List<Teacher> data = teacherMapper.teacherPages(map);
		page.setPageData(data);
		
		return page;
	}

	//查看详情
	@Override
	public Teacher getTeacherById(Integer teacherId) {
		return teacherMapper.getTeacher(teacherId);
	}

	//删除
	@Override
	public int deleteTeacher(Integer teacherId) {
		return teacherMapper.delete(teacherId);
	}

	//修改
	@Override
	public int updateTeacher(Teacher teacher) {
		return teacherMapper.update(teacher);
	}

	@Override
	public int add(Teacher teacher) {
        return teacherMapper.add(teacher);
    }
	
	
}
